package com.example.studentcoursesysteam.Repository;

import com.example.studentcoursesysteam.Bean.Course;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

@Repository
public interface CourseRepository extends JpaRepository<Course,Integer> {
    boolean existsByCode(String code);

    @Transactional
    @Modifying
    @Query(value = "delete from course where code =:code",nativeQuery = true)
    Integer getDeleteByCode(String code);

    @Transactional
    @Modifying
    @Query(value = "delete from course where teacher_code =:code",nativeQuery = true)
    Integer getDeleteByTeacherCode(String code);

    Page<Course> findByNameLike(String name,Pageable pageable);


}
